package com.travelsky.airchina.boarding.dao.impl.hibernate;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.travelsky.airchina.boarding.dao.BrandModelDAO;
import com.travelsky.airchina.boarding.domain.BrandModel;
import com.travelsky.airchina.boarding.dto.BrandModelVO;


@Repository("brandModelDAO")
public class BrandModelDAOImpl extends GenericDAOHibernate<BrandModel, Long,BrandModelDAO> implements BrandModelDAO  {
	@Autowired
	public BrandModelDAOImpl(SessionFactory sessionFactory){
		this.setSessionFactory(sessionFactory);
	}
	/**
	 * @param id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BrandModelVO> findBrandModelsByBrandId(Long id) {
		String hql = "select id,name from BrandModel where brand.id = ? and status = ? ";
		List<Object[]> list0 = this.getHibernateTemplate().find(hql,new Object[]{id,"1"});
		if(list0!=null && list0.size()>0){
			List<BrandModelVO> list = new ArrayList<BrandModelVO>();
			for(Object[] temp:list0){
				BrandModelVO o = new BrandModelVO();
				o.setId((Long)temp[0]);
				o.setName((String)temp[1]);
				list.add(o);
			}
			return list;
		}
		return null;
	}

}
